<!DOCTYPE html>
<html>
	<head>
		<title>设置个人资料</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/myInfo.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/plugins/form/jquery.form.js"></script>
		<script src="/js/common.js"></script>
		<script src="/js/checkLogin.js"></script>
		<script>
			$(function () {
				//回显用户信息
				$('.info').renderValues(user);
				//回显背景图片
				$('.myBg').css("background-image","url("+user.coverImgUrl+")");
				//保存
				$('#saveBtn').click(function () {
					$('#infoForm').ajaxSubmit({
						url:baseUrl+"/users/"+user.id,
						success:function (data) {
							sessionStorage.setItem('user',JSON.stringify(data.data));
							window.location.href = "/mine/profiles.html";
						}
					});
				});

				//定义一个标记,用来判断是图片上传还是背景上传
				var flag = false;
				//头像上传的点击事件
				$('#headBtn').click(function () {
					flag = true;
					$('#fileInput').click();
				});
				//背景上传的点击事件
				$('#coverBtn').click(function () {
					flag = false;
					$('#fileInput').click();
				});
				//标签内容发生改变的事件
				$('#fileInput').change(function () {
					$('#imgForm').ajaxSubmit({
						url:baseUrl+'/images',
						method:"post",
						success:function (data) {
							if (flag) {
								$('#headImg').attr('src',data.url);
								$('input[name="headImgUrl"]').val(data.url);
							}else {
								$('.myBg').css("background-image","url("+data.url+")");
								$('input[name=coverImgUrl]').val(data.url);
							}
						}
					});
				});

			});


		</script>
	</head>

	<body>
		<form id="imgForm" >
			<input type="file" id="fileInput" name="file" hidden/>
		</form>

		<div class="search-head">
			<div class="row nav-search">
				<div class="col">
					<a href="javascript:window.history.go(-1);">
						<span>取消</span>
					</a>
				</div>
				<div class="col">
					<span>设置个人资料</span>
				</div>
				<div class="col" >
					<a href="#" id="saveBtn" >
						<span>保存</span>
					</a>
				</div>
			</div>
		</div>

		<div class="container info">
			<div class="myBg">
				<img id="headImg"  class="rounded-circle" render-src="headImgUrl"/>
				<!--编辑头像按钮-->
				<div class="editHead" id="headBtn" ><i class="fa fa-pencil-square fa-lg " aria-hidden="true"></i></div>
				<button  class="btn btn-outline-light ibtn " id="coverBtn">设置背景</button>
			</div>

			<form id="infoForm" method="post">
				<input type="hidden" name="_method" value="put">
				<input type="hidden" name="id" render-value="id">
				<!--头像和背景的路径地址-->
				<input type="hidden" name="headImgUrl" render-value="headImgUrl">
				<input type="hidden" name="coverImgUrl" render-value="coverImgUrl">
				<!--携带邮箱信息到后台,为了更新操作后共享到前台-->
				<input type="hidden" name="email" render-value="email">

				<label>昵称</label><input type="text" name="nickName" class="form-control" render-value="nickName">
				<label>性别</label><select class="form-control" name="gender" render-value="gender">
						<option value="-1">保密</option>
						<option value="1">男</option>
						<option value="0">女</option>
					</select>
				<label>地区</label><input type="text" name="place"  class="form-control" render-value="place">
				<label>签名</label><textarea name="sign" class="form-control" rows="5" render-value="sign"></textarea>
			</form>
		</div>
		
		
		
	</body>
</html>
